package cn.sumpu.app.guoguojie.biz.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import cn.sumpu.app.guoguojie.biz.IdentifierBiz;
import cn.sumpu.app.guoguojie.biz.MemberBiz;
import cn.sumpu.app.guoguojie.biz.PictorialBiz;
import cn.sumpu.app.guoguojie.biz.PictorialTopicBiz;
import cn.sumpu.app.guoguojie.dao.PictorialDao;
import cn.sumpu.app.guoguojie.dao.PictorialTopicDao;
import cn.sumpu.app.guoguojie.domain.DoingPictorial;
import cn.sumpu.app.guoguojie.domain.DoingPictorialTopic;
import cn.sumpu.app.guoguojie.domain.Member;
import cn.sumpu.app.guoguojie.domain.PictorialDoing;
import cn.sumpu.app.guoguojie.domain.PictorialTopic;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;
import cn.sumpu.app.guoguojie.util.Common;
import cn.sumpu.app.guoguojie.util.Constant;
import cn.sumpu.app.guoguojie.util.PageModel;

public class PictorialTopicBizImpl implements PictorialTopicBiz {

    private PictorialTopicDao pictorialTopicDao;
    private PictorialDao      pictorialDao;
    @Autowired
    private PictorialBiz      pictorialBiz;
    @Autowired
    private IdentifierBiz     identifierBiz;
    @Autowired
    private MemberBiz     memberBiz;
    public void setPictorialTopicDao(PictorialTopicDao pictorialTopicDao) {
        this.pictorialTopicDao = pictorialTopicDao;
    }

    public void setPictorialDao(PictorialDao pictorialDao) {
        this.pictorialDao = pictorialDao;
    }

    //添加画报主题
    @Override
    public void addPictorialTopic(PictorialTopic pictorialTopic) throws AppBusinessException {
        Integer minSort = getTopicMinSort();
        if (minSort != null) {
            pictorialTopic.setSort(minSort - 1);
        }
        pictorialTopicDao.addPictorialTopic(pictorialTopic);
    }

    //查询所有画报主题
    @Override
    public List<PictorialTopic> getPictorialTopicAll() throws AppBusinessException {
        return pictorialTopicDao.getPictorialTopicAll(null);
    }

    @Override
    public List<PictorialTopic> getTopicNoLock() throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("isLock", false);
        return pictorialTopicDao.getPictorialTopicAll(map);
    }

    @Override
    public PictorialTopic getPictorialTopicId(String topicId) throws AppBusinessException {
        if (Common.empty(topicId)) {
            return null;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("identifier", topicId);
        List<PictorialTopic> ptList = pictorialTopicDao.getPictorialTopicAll(map);
        if (ptList != null && ptList.size() > 0) {
            return ptList.get(0);
        }
        return null;
    }

    @Override
    public PictorialTopic getPictorialTopicBonus(String bonus) throws AppBusinessException {
        if (Common.empty(bonus)) {
            return null;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("bonus", bonus);
        List<PictorialTopic> ptList = pictorialTopicDao.getPictorialTopicAll(map);
        if (ptList != null && ptList.size() > 0) {
            return ptList.get(0);
        }
        return null;
    }

    //更新画报主题
    @Override
    public void updatePictorialTopicById(PictorialTopic pictorialTopic) throws AppBusinessException {
        pictorialTopicDao.updatePictorialTopicById(pictorialTopic);
    }

    //删除画报主题
    @Override
    public void deletePictorialTopicById(String identifier) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("identifier", identifier);
        pictorialTopicDao.deletePictorialTopicById(map);
        pictorialTopicDao.deletePictorialTopicByTopic(identifier);
    }

    //给画报添加主题
    @Override
    public void addDoingPictorialTopic(String pictorial, String topicId, Date gmtCreated, Date gmtModified) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorial);
        map.put("topicId", topicId);
        map.put("gmtCreated", gmtCreated);
        map.put("gmtModified", gmtModified);
        pictorialTopicDao.addDoingPictorialTopic(map);
    }

    //删除画报主题
    @Override
    public void deleteDoingPictorialTopic(String pictorial) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorial);
        pictorialTopicDao.deleteDoingPictorialTopic(map);
    }

    //根据名称查询画报主题的个数
    @Override
    public int getPictorialTopicByName(String name) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("name", name);
        return pictorialTopicDao.getPictorialTopicByName(map);
    }

    //根据画报ID查询画报主题
    @Override
    public List<PictorialTopic> getPictorialTopicByID(String pictorialId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorialId);
        return pictorialTopicDao.getPictorialTopicByID(map);
    }

    @Override
    public List<DoingPictorial> getLastTopicMember(String topicId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("topicId", topicId);
        return pictorialTopicDao.getLastTopicMember(map);
    }

    @Override
    public PageModel getLastTopic(int page) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        int pageSize = 9;
        Integer startId = (page - 1) * pageSize;
        map.put("startId", startId);
        map.put("pageSize", pageSize);
        map.put("type", Constant.PIC_TOPIC_TYPE_COMMON);
        List<PictorialTopic> lastTopic9 = pictorialTopicDao.getPictorialTopicAll(map);
        for (PictorialTopic lastTopic : lastTopic9) {
            String topicId = lastTopic.getIdentifier();
            //			画报数
            int count = pictorialBiz.getPictorialCountNew(null, topicId);
            lastTopic.setPicAmount(count);
            map.put("topicId", topicId);
            List<String> lastPictorial6 = pictorialTopicDao.getLastPictorail6(map);
            if (lastPictorial6 != null && lastPictorial6.size() > 0) {
                Map<String, Object> map2 = new HashMap<String, Object>();
                for (int i = 1; i <= lastPictorial6.size(); i++) {
                    switch (i) {
                        case 1: {
                            map2.put("pictorial1", lastPictorial6.get(i - 1));
                            break;
                        }
                        case 2: {
                            map2.put("pictorial2", lastPictorial6.get(i - 1));
                            break;
                        }
                        case 3: {
                            map2.put("pictorial3", lastPictorial6.get(i - 1));
                            break;
                        }
                        case 4: {
                            map2.put("pictorial4", lastPictorial6.get(i - 1));
                            break;
                        }
                        case 5: {
                            map2.put("pictorial5", lastPictorial6.get(i - 1));
                            break;
                        }
                        case 6: {
                            map2.put("pictorial6", lastPictorial6.get(i - 1));
                            break;
                        }
                    }
                }
                List<String> lastPicUrl = pictorialTopicDao.getLastPicUrl6(map2);
                lastTopic.setPicUrlList(lastPicUrl);
            }

        }
        int count = pictorialTopicDao.getPictorialTopicAllCount(map);
        PageModel pm = new PageModel();
        pm.setCurrentPage(page);
        pm.setList(lastTopic9);
        pm.setPageSize(pageSize);
        pm.setTotalRecord(count);
        pm.setTotalPage((count + pageSize - 1) / pageSize);
        return pm;
    }

    public void updatePictorialTopic(DoingPictorial dp) throws AppBusinessException {
        if (dp == null || Common.empty(dp.getIdentifier()))
            return;
        List<PictorialTopic> ptListed = getPictorialTopicByID(dp.getIdentifier());
        deleteDoingPictorialTopic(dp.getIdentifier());
        String[] str = dp.getPictorialTopic().split(",");
        for (String topicId : str) {
            if (!Common.empty(topicId)) {
                Date gmtCreated = new Date();
                Date gmtModified = new Date();
                for (PictorialTopic pictorialTopic : ptListed) {
                    if (pictorialTopic.getIdentifier().equals(topicId)) {
                        gmtCreated = pictorialTopic.getGmtCreated();
                        gmtModified = pictorialTopic.getGmtModified();
                        break;
                    }
                }
                addDoingPictorialTopic(dp.getIdentifier(), topicId, gmtCreated, gmtModified);
            }
        }

    }

    @Override
    public void updatePictorialSort(String pictorial, String pictorialTopic, Integer sort) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorial);
        map.put("pictorialTopic", pictorialTopic);
        map.put("sort", sort);
        pictorialTopicDao.updatePictorialSort(map);
    }

    @Override
    public void delPicFromTopic(String pictorial, String pictorialTopic) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorial);
        map.put("pictorialTopic", pictorialTopic);
        pictorialTopicDao.delPicFromTopic(map);
    }

    /**
     * author BruceZhang
     * @return	查询所有画报主题
     * @throws AppBusinessException
     */
    @Override
    public PageModel pictorialGrid(Integer pagesize, Integer page) throws AppBusinessException {
        if (page == null || page < 1) {
            page = 1;
        }
        if (pagesize == null || pagesize < 1) {
            pagesize = 10;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("startId", (page - 1) * pagesize);
        map.put("pageSize", pagesize);
        List<PictorialTopic> list = pictorialTopicDao.getPictorialTopicAll(map);
        int count = pictorialTopicDao.getPictorialTopicAllCount(map);
        PageModel pm = new PageModel();
        pm.setCurrentPage(page);
        pm.setList(list);
        pm.setPageSize(pagesize);
        pm.setTotalRecord(count);
        pm.setTotalPage((count + pagesize - 1) / pagesize);
        return pm;
    }

    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)
    @Override
    public void moveTopicSort(String topicId, String moveType) throws AppBusinessException {
        PictorialTopic topic = getTopicById(topicId);
        if (!Common.empty(topic)) {
            PictorialTopic changeTopic = getChangeTopic(topic, moveType);
            if (!Common.empty(changeTopic)) {
                changeTopicSort(topic, changeTopic);
            }
        }
    }

    private PictorialTopic getChangeTopic(PictorialTopic topic, String moveType) throws AppBusinessException {
        if (Common.empty(topic)) {
            return null;
        }
        int sort = topic.getSort();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("moveType", moveType);
        map.put("sort", sort);
        List<PictorialTopic> list = pictorialTopicDao.getPictorialTopic(map);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    private void changeTopicSort(PictorialTopic topic1, PictorialTopic topic2) throws AppBusinessException {
        if (!Common.empty(topic1) && !Common.empty(topic2)) {
            int sort1 = topic1.getSort();
            int sort2 = topic2.getSort();
            topic1.setSort(sort2);
            topic2.setSort(sort1);
            pictorialTopicDao.updatePictorialTopicById(topic1);
            pictorialTopicDao.updatePictorialTopicById(topic2);
        }
    }

    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)
    @Override
    public void movePictorialSort(String topicId, String pictorialId, String moveType) throws AppBusinessException {
        DoingPictorialTopic topicPictorial = getTopicPictorialById(topicId, pictorialId);
        if (!Common.empty(topicPictorial)) {
            DoingPictorialTopic changePictorialTopic = getChangeTopicPictorial(topicPictorial, moveType);
            if (!Common.empty(changePictorialTopic)) {
                changeTopicPictorialSort(topicPictorial, changePictorialTopic);
            }
        }
    }

    private DoingPictorialTopic getChangeTopicPictorial(DoingPictorialTopic topicPictorial, String moveType) throws AppBusinessException {
        if (Common.empty(topicPictorial)) {
            return null;
        }
        int sort = topicPictorial.getSort();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("topicId", topicPictorial.getPictorialTopic());
        map.put("moveType", moveType);
        map.put("sort", sort);
        List<DoingPictorialTopic> list = pictorialTopicDao.getTopicPictorial(map);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    private void changeTopicPictorialSort(DoingPictorialTopic topicPictorial1, DoingPictorialTopic topicPictorial2) throws AppBusinessException {
        if (!Common.empty(topicPictorial1) && !Common.empty(topicPictorial2)) {
            int sort1 = topicPictorial1.getSort();
            int sort2 = topicPictorial2.getSort();
            topicPictorial1.setSort(sort2);
            topicPictorial2.setSort(sort1);
            pictorialTopicDao.updateTopicPictorial(topicPictorial1);
            pictorialTopicDao.updateTopicPictorial(topicPictorial2);
        }
    }

    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)
    @Override
    public void moveDoingSort(String pictorialId, String doingId, String moveType) throws AppBusinessException {
        PictorialDoing pictorialDoing = getPictorialDoingById(pictorialId, doingId); 
        if (!Common.empty(pictorialDoing)) {
            PictorialDoing changePictorialDoing = getChangePictorialDoing(pictorialDoing, moveType);
            changePictorialDoingSort(pictorialDoing, changePictorialDoing);
        }
    }

    private PictorialDoing getChangePictorialDoing(PictorialDoing pictorialDoing, String moveType) throws AppBusinessException {
        if (Common.empty(pictorialDoing)) {
            return null;
        }
        int sort = pictorialDoing.getSort();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorialDoing.getPictorial());
        map.put("moveType", moveType);
        map.put("sort", sort);
        List<PictorialDoing> list = pictorialTopicDao.getPictorialDoing(map);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    private void changePictorialDoingSort(PictorialDoing pictorialDoing1, PictorialDoing pictorialDoing2) throws AppBusinessException {
        if (!Common.empty(pictorialDoing1) && !Common.empty(pictorialDoing2)) {
            int sort1 = pictorialDoing1.getSort();
            int sort2 = pictorialDoing2.getSort();
            pictorialDoing1.setSort(sort2);
            pictorialDoing2.setSort(sort1);
            pictorialTopicDao.updatePictorialDoing(pictorialDoing1);
            pictorialTopicDao.updatePictorialDoing(pictorialDoing2);
        }
    }

    @Override
    public PictorialTopic getTopicById(String topicId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("identifier", topicId);
        List<PictorialTopic> list = pictorialTopicDao.getPictorialTopic(map);
        if (list != null && list.size() == 1) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public DoingPictorialTopic getTopicPictorialById(String topicId, String pictorialId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorialId);
        map.put("topicId", topicId);
        List<DoingPictorialTopic> list = pictorialTopicDao.getTopicPictorial(map);
        if (list != null && list.size() == 1) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public PictorialDoing getPictorialDoingById(String pictorialId, String doingId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorialId);
        map.put("doing", doingId);
        List<PictorialDoing> list = pictorialTopicDao.getPictorialDoing(map);
        if (list != null && list.size() == 1) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public Integer getTopicMinSort() throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        return pictorialTopicDao.getTopicMinSort(map);
    }

    @Override
    public Integer getTopicPictorialMinSort(String topicId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("topicId", topicId);
        return pictorialTopicDao.getTopicPictorialMinSort(map);
    }

    @Override
    public Integer getPictorialDoingMinSort(String pictorialId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorialId);
        return pictorialTopicDao.getPictorialDoingMinSort(map);
    }

    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)
    @Override
    public void saveTopicPictorial(String topicId, DoingPictorial dp) throws AppBusinessException {
        if (!Common.empty(dp)) {
            if (Common.empty(dp.getIdentifier())) {
                String id = identifierBiz.generateId("doing_pictorial");
                dp.setIdentifier(id);
                pictorialDao.insertPictorial(dp);
                if (!Common.empty(topicId)) {
                    Integer minSort = getTopicPictorialMinSort(topicId);
                    DoingPictorialTopic dpt = new DoingPictorialTopic();
                    dpt.setSort(0);
                    dpt.setPictorialTopic(topicId);
                    dpt.setPictorial(id);
                    if (minSort != null) {
                        dpt.setSort(minSort - 1);
                    }
                    pictorialTopicDao.insertTopicPictorial(dpt);
                }
            } else {
                pictorialDao.updatePictorial(dp);
            }
        }
    }

    @Override
    public void savePictorialDoing(PictorialDoing pictorialDoing) throws AppBusinessException {
        if (!Common.empty(pictorialDoing)) {
            Integer minSort = getPictorialDoingMinSort(pictorialDoing.getPictorial());
            pictorialDoing.setSort(0);
            if (minSort != null) {
                pictorialDoing.setSort(minSort - 1);
            }
            pictorialTopicDao.insertPictorialDoing(pictorialDoing);
        }
    }

    @Override
    public PageModel getTopicPictorial(String topicId, Integer page, Integer pageSize) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        page = page == null ? 1 : page;
        int size = pageSize == null ? 10 : pageSize;
        map.put("startId", (page - 1) * size);
        map.put("pageSize", size);
        map.put("topicId", topicId);
        int count = pictorialTopicDao.getTopicPictorialCount(map);
        PageModel pm = new PageModel();
        pm.setCurrentPage(page);
        List<DoingPictorialTopic> list = pictorialTopicDao.getTopicPictorial(map);
        pm.setList(list);
        pm.setPageSize(size);
        pm.setTotalRecord(count);
        pm.setTotalPage((count + size - 1) / size);
        return pm;
    }
    
    public List<DoingPictorialTopic> getMobileDoingPic()throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("topicId", Constant.MOBILE_TOPIC_ID);
        map.put("display", "01"); 
        return pictorialTopicDao.getTopicPictorial(map); 
    }

    @Override
    public PageModel getPictorial(Integer page, Integer pageSize, String title) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        page = page == null ? 1 : page;
        int size = pageSize == null ? 10 : pageSize;
        map.put("startId", (page - 1) * size);
        map.put("pageSize", size);
        if (!Common.empty(title)) {
            map.put("title", "%" + title + "%");
        }
        int count = pictorialTopicDao.getPictorialCount(map);
        PageModel pm = new PageModel();
        pm.setCurrentPage(page);
        List<DoingPictorial> list = pictorialTopicDao.getPictorial(map);

        pm.setList(list);
        pm.setPageSize(size);
        pm.setTotalRecord(count);
        pm.setTotalPage((count + size - 1) / size);
        return pm;
    }

    @Override
    public PageModel getPictorialDoing(String pictorialId, Integer page, Integer pageSize) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>(); 
        page = page == null ? 1 : page;
        int size = pageSize == null ? 10 : pageSize; 
        map.put("startId", (page - 1) * size);
        map.put("pageSize", size);
        map.put("pictorial", pictorialId);
        int count = pictorialTopicDao.getPictorialDoingCount(map); 
        PageModel pm = new PageModel();
        pm.setCurrentPage(page); 
        List<PictorialDoing> list = pictorialTopicDao.getPictorialDoing(map);
        pm.setList(list);
        pm.setPageSize(size);
        pm.setTotalRecord(count);
        pm.setTotalPage((count + size - 1) / size);
        return pm;
    }
    
    public PictorialDoing getPicDoingMobMov(String mobileMove,String currentDoingId,String pictorialId)throws AppBusinessException{
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorialId);
        map.put("mobileMove", mobileMove);
        map.put("currentDoingId", currentDoingId);
        List<PictorialDoing> list = pictorialTopicDao.getPictorialDoing(map);
        if(list != null && list.size() > 0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public DoingPictorial getPictorialById(String pictorialId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("identifier", pictorialId);
        List<DoingPictorial> list = pictorialTopicDao.getPictorial(map);
        if (list != null && list.size() == 1) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public void setPictorialCover(String pictorialId, String cover) throws AppBusinessException {
        DoingPictorial pict = getPictorialById(pictorialId);
        pict.setCover(cover);
        pictorialDao.updatePictorial(pict);
    }

    @Override
    public void deletePictorialDoing(String pictorialId, String doingId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pictorial", pictorialId);
        map.put("doing", doingId);
        pictorialTopicDao.deletePictorialDoing(map);
    }
    
    /**
     * vimple,话题得到画报
     * @param topicId
     * @return
     * @throws AppBusinessException
     * @see cn.sumpu.app.guoguojie.biz.PictorialTopicBiz#getPictorialListByTid(java.lang.String)
     */
    @Override
    public List<DoingPictorialTopic> getPictorialListByTid(String topicId) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("topicId", topicId);
        List<DoingPictorialTopic> list = pictorialTopicDao.getTopicPictorial(map);
        for(DoingPictorialTopic dpt:list){ 
            Map<String, Object> map2 = new HashMap<String, Object>();
            map2.put("startId", 0);
            map2.put("pageSize", 8);
            map2.put("pictorial", dpt.getPictorial());
            List<PictorialDoing> doingList = pictorialTopicDao.getPictorialDoing(map2);
            dpt.setDoingList(doingList);
        }
        return list;
    }
    
    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)
    @Override
    public void saveTopicPictorialForDoingPic(String topicId, DoingPictorial dp) throws AppBusinessException {
        if (!Common.empty(dp)) {
                String id = identifierBiz.generateId("doing_pictorial");
                dp.setIdentifier(id);
                pictorialDao.insertPictorial(dp);
                if (!Common.empty(topicId)) {
                    Integer minSort = getTopicPictorialMinSort(topicId);
                    DoingPictorialTopic dpt = new DoingPictorialTopic();
                    dpt.setSort(0);
                    dpt.setPictorialTopic(topicId);
                    dpt.setPictorial(id);
                    if (minSort != null) {
                        dpt.setSort(minSort - 1);
                    }
                    pictorialTopicDao.insertTopicPictorial(dpt);
                }
        }
    }
    
    /**
     * //图片画报列表
     */
    @Override
    public PageModel getTopicPictorialForAmoy(String topicId, Integer page, Integer pageSize) throws AppBusinessException {
        Map<String, Object> map = new HashMap<String, Object>();
        page = page == null ? 1 : page;
        int size = pageSize == null ? 10 : pageSize;
        map.put("startId", (page - 1) * size);
        map.put("pageSize", size);
        map.put("topicId", topicId); 
        int count = pictorialTopicDao.getTopicPictorialCount(map);
        PageModel pm = new PageModel();
        pm.setCurrentPage(page);
        List<DoingPictorialTopic> list = pictorialTopicDao.getTopicPictorial(map);
        for(DoingPictorialTopic dpt:list){ 
            Map<String, Object> map2 = new HashMap<String, Object>();
            map2.put("startId", 0);
            map2.put("pageSize", 3);
            map2.put("pictorial", dpt.getPictorial());
            List<PictorialDoing> doingList = pictorialTopicDao.getPictorialDoing(map2);
            dpt.setDoingList(doingList);
            Member member=memberBiz.getLoginMemberById(dpt.getPictorialObj().getMember());
            dpt.setNickname(member.getNickname());
            dpt.setAvatar(member.getAvatar());
            dpt.setImageServer(member.getImageServer());
        }
        pm.setList(list);
        pm.setPageSize(size);
        pm.setTotalRecord(count);
        pm.setTotalPage((count + size - 1) / size);
        return pm;
    }
    //图片微博底层展示页面
    @Override 
    public  List<PictorialDoing> getPictorialDoingForAmoy(String plId) throws AppBusinessException {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("pictorial", plId);
            List<PictorialDoing> doingList = pictorialTopicDao.getPictorialDoing(map);
            return doingList;
    }
    @Override  
    public  List<DoingPictorial> getTopicPictorialForname(String TId) throws AppBusinessException {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("topicId", TId);
            List<DoingPictorial> list = pictorialTopicDao.getDoingPictorialForname(map);
            for(DoingPictorial dp :list ){
                Member member=memberBiz.getLoginMemberById(dp.getMember());
                dp.setNickname(member.getNickname());
                dp.setAvatar(member.getAvatar());
                dp.setImageServer(member.getImageServer());
            }
            return list;
    }
    @Override  
    public  List<DoingPictorial> getOneForcreator(Map<String, Object> map) throws AppBusinessException {
            List<DoingPictorial> list = pictorialTopicDao.getOneForcreator(map);
            return list;
    }
    
    
}
